<!-- Dom模板 -->
<template>
  <div class="AttBox" ref="waiceng">
    <div class="Att_move" ref="neiceng" @touchstart="touchstart" @touchend="touchend">
      <!-- 关注简略信息 -->
      <div class="myAtt">
        <div class="myAttUser">
          <div class="myAttUserAvatar">
            <img :src="tokens?($store.state.login.loginuser.user_img?$store.state.login.loginuser.user_img:'../../../static/img/touxiang.jpg'):'../../../static/img/touxiang.jpg'" alt="" />
          </div>
          <div class="myAttUserAttNum">
            <p>我共关注了</p>
            <div class="AttNum">
              <p><span>{{authorNum.length}}</span>个作者</p>
              <p><span>{{listenrs.length}}</span>个声控主播</p>
            </div>
          </div>
        </div>
        <div class="myAttUserAtt" v-if="attArr.length===0?false:true">
          <div
            class="Avatar"
            ref="Avatar"
            v-for="(item, index) in attArr"
            :key="index"
          >
            <img :src="item.user_img" alt="" />
          </div>
          <div class="myAttUserAttGo" ref="arrow">></div>
        </div>
      </div>
      <!-- 关注主播 ,作者-->
      <div class="myAttAuthor">
        <!-- 每一个作者主播 -->
        <div class="myAttAuthorCon" v-for="(item,index) in tokens?$store.state.login.loginuserMsg.guanzhu.circle:0" :key="index">
          <div class="myAttAuthorImg" v-if="item.img_urlo==='null'?false:true">
            <img :src="item.img_urlo" alt="" />
          </div>
          <div class="myAttAuthorMood">
            {{item.datatext}}
          </div>
          <div class="myAttAuthorFooter">
            <div class="myAttAuthorAvatar">
              <div class="myAttAuthorAvatarImg">
                <img :src="item.user_img" alt="" />
              </div>
              
              <span class="myAttAuthorName">{{item.name}}</span>
            </div>
           
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import a from './a'; // 引入组件
import { Toast } from "vant";
import minxins from './socialMixin.js'
export default {
  name: "",
  mixins:[minxins],
  data() {
    return {
      msg: "测试",
      authorNum:[],
      listenrs:[],
      attArr:[],
      tokens:sessionStorage.getItem('token')
    };
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    if (sessionStorage.getItem("userId")) {
           this.$store.state.login.loginuserMsg.guanzhu.prople.forEach(item=>{
             if(item.type==='1'||(item.type==='1'&&item.type==='2')){
               this.authorNum.push(item)
             }
             else if(item.type==='2'||(item.type==='1'&&item.type==='2')){
               this.listenrs.push(item)
             }
           })
    }
    if(sessionStorage.getItem('token')){
      this.attArr= this.$store.state.login.loginuserMsg.guanzhu.prople.slice(0,3)
    }
    
    console.log(this.attArr)
    if(this.attArr.length>0){
      this.$nextTick(() => {
      this.$refs["Avatar"].forEach((item, index) => {
        item.style.left = `${(index * item.offsetWidth) / 1.65}px`;
      });
    });
    }
  },
  // Vue方法定义
  methods: {
    touchstart(e) {
      let start = {};
      let flag = true;
      let diffY = null;
      let end = null;
      start = {
        x: e.touches[0].clientX,
        y: e.touches[0].clientY,
      };
      this.$refs["neiceng"].style.transition = "";
      this.$refs["neiceng"].addEventListener("touchmove", (e) => {
        end = {
          x: e.touches[0].clientX,
          y: e.touches[0].clientY,
        };
        if (Math.abs(end.x - start.x) > Math.abs(end.y - start.y)) {
          flag = false;
        } else {
          flag = true;
        }
        if (this.$refs["waiceng"].scrollTop === 0 && flag) {
          if (this.arr.length <= 1) {
            this.arr.push(e.touches[0].clientY);
          }
          diffY = end.y - this.arr[0];
          if (Math.abs(diffY) > 180) {
            return;
          }
          this.$refs["neiceng"].style.transform = `translateY(${diffY * 0.4}px)`;
        }
        if (
          this.$refs["waiceng"].scrollTop + 670 >=
            this.$refs["neiceng"].offsetHeight &&
          flag
        ) {
          if (this.arr.length <= 1) {
            this.arr.push(e.touches[0].clientY);
          }
          end = {
            y: e.touches[0].clientY,
          };
          diffY = end.y - this.arr[0];
          if (Math.abs(diffY) > 170) {
            return;
          }
          this.$refs["neiceng"].style.transform = `translateY(${diffY * 0.4}px)`;
        }
      });
    },
    touchend() {
      this.$refs["neiceng"].style.transition = "all 0.2s linear";
      this.$refs["neiceng"].style.transform = `translateY(0)`;
      this.arr = [];
      this.$refs["neiceng"].removeEventListener("touchstart", this.touchstart);
      this.$refs["neiceng"].removeEventListener("touchmove", this.touchstart);
    },
  },
};
</script>

<style scoped>
@import url('../../../static/fonts/iconfont.css');
/* @import url(''); 引入css类 */
.loding{
  width: .9rem;
  height: .9rem;
  line-height: .7.5rem;
  border-radius: 50%;
  box-shadow: 2px 2px 4px 2px rgba(0, 0, 0, 0.1);
  position: absolute;
  left: calc(50vw - .5rem);
  color: rgb(121, 121, 121);
  text-align: center;
  font-size: .64rem !important;
  padding: .08rem;
}
.anim_loding{
  animation: anim_rotate .8s linear infinite both;;
}
@keyframes anim_rotate {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}
.AttBox{
  padding: .026667rem .266667rem;
  width: 100vw;
  height: calc(100vh - 4.08rem);
  overflow-y: auto;
  position: relative;
  
}
.Att_move{
  background: white;
}
.myAtt {
  width: 94.66%;
  height: 1.733333rem;
  border-radius: 8px;
  background: rgb(255, 255, 255);
  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  margin: 0 auto .4rem;
  display: flex;
  padding: 0.266667rem;
}
.myAttUser {
  width: 65%;
  display: flex;
}
/* 右侧关注小头像 */
.myAttUserAtt {
  display: flex;
  position: relative;
  margin: 0.266667rem 0 0 1rem;
}
.myAttUserAttNum {
  margin: 0 0 0 0.4rem;
  padding: 0.1rem 0;
}
.myAttUserAttNum > p {
  color: rgb(77, 77, 77);
}
.AttNum {
  display: flex;
  margin-top: 0.25rem;
  font-weight: 600;
}

.myAttUserAvatar {
  width: 1.173333rem;
  height: 1.173333rem;
  border-radius: 50%;
  overflow: hidden;
}
.myAttUserAttGo {
  position: absolute;
  left: 1.6rem;
  top: 0.075rem;
  color: rgb(169, 169, 169);
  width: 0.4rem;
  height: 0.4rem;
  transform: scaleY(1.5);
  font-weight: 900;
}
.Avatar {
  width: 0.64rem;
  height: 0.64rem;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid white;
  position: absolute;
}
.Avatar img {
  width: 100%;
  height: 100%;
}
.myAttUserAvatar img {
  width: 100%;
  height: 100%;
}
/* 每个主播 */
.myAttAuthor{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.myAttAuthorCon {
  width: 4.5rem;
  min-width:3rem;
  border-radius: 0.213333rem;
  overflow: hidden;
  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
  margin: .306667rem 0;
  box-sizing: border-box;
  padding:  0 0 .133333rem;
}
.myAttAuthorImg {
  width: 4.586667rem;
  height: 5.146667rem;
  overflow: hidden;
  position: relative;
}
.myAttAuthorImg img {
  width: 100vw;
  /* height: 100%; */
  position: absolute;
  left: -20%;

}
.myAttAuthorMood {
  font-size: 0.426667rem;
  font-family: PingFangSC-regular;
  width: 100%;
  height: 1.3rem;
  padding: 0.133333rem 0 0 0.133333rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.myAttAuthorAvatar{
  display: flex;
}
.myAttAuthorName{
  display: inline-block;
  line-height: .55rem;
  margin-left: .266667rem;
}
.myAttAuthorAvatarImg{
  width: .58rem;
  height: .58rem;
  border-radius: 50%;
  overflow: hidden;
  
}
.myAttAuthorAvatarImg img{
  width: 100%;
  height: 100%;
}
.myAttAuthorFooter{
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
  padding: .266667rem .213333rem;
}
.praise{
  margin-top: 0.08rem;
}

</style>